/*
 * Copyright (c) 2011, Julien Lamy
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * Neither the name of the project's author nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#ifndef e514f7ef_0c79_4e84_80d1_334b44c564b2
#define e514f7ef_0c79_4e84_80d1_334b44c564b2

#include <iosfwd>
#include <map>
#include <stdint.h>

#include <QString>

#include "config.h"
#include "dataobject.h"
#include "stringcontainer.h"

/**
 * @brief A musical track.
 */
class BABELPOD_EXPORT Track : public StringContainer
{
public :

    uint32_t unique_id; // 0
    uint32_t visible; // 4
    uint32_t file_type; // 8, Space-padded string
    uint8_t type_1; // 12
    uint8_t type_2; // 13
    uint8_t compilation; // 14
    uint8_t rating; // 15
    uint32_t last_modified_time; // 16
    uint32_t size; // 20
    uint32_t length; // 24
    uint32_t track_number; // 28
    uint32_t total_tracks; // 32
    uint32_t year; // 36
    uint32_t bit_rate; // 40
    uint32_t sample_rate; // 44
    uint32_t volume; // 48
    uint32_t start_time; //52
    uint32_t stop_time; // 56
    uint32_t sound_check; // 60
    uint32_t play_count; // 64
    uint32_t play_count_2; // 68
    uint32_t last_played_time; // 72
    uint32_t disk_number; // 76
    uint32_t total_disks; // 80
    uint32_t user_id; // 84
    uint32_t date_added; // 88
    uint32_t bookmark_time; // 92
    uint64_t db_id; // 96
    uint8_t checked; // 104
    uint8_t application_rating; // 105
    uint16_t bpm; // 106
    uint16_t artwork_count; // 108
    uint16_t unknown_1; // 110
    uint32_t artwork_size; // 112
    uint32_t unknown_2; // 116
    uint32_t sample_rate_2; // 120
    uint32_t date_released; // 124
    uint16_t unknown_3; // 128
    uint16_t explicit_flag; // 130
    uint32_t unknown_4; // 132
    uint32_t unknown_5; // 136
    uint32_t skip_count; // 140
    uint32_t last_skipped; // 144
    uint8_t has_artwork; // 148
    uint8_t skip_when_shuffling; // 149
    uint8_t remember_playback_position; // 150
    uint8_t flag_4; // 151
    uint64_t db_id_2; // 152
    uint8_t lyrics_flags; // 160
    uint8_t movie_file_flags; // 161
    uint8_t played_mark; // 162
    uint8_t unknown_6; // 163
    uint32_t unknown_7; // 164
    uint32_t pre_gap; // 168
    uint64_t sample_count; // 172
    uint32_t unknown_8; // 180
    uint32_t post_gap; // 184
    uint32_t unknown_9; // 188
    uint32_t media_type; // 192
    uint32_t season_number; // 196
    uint32_t episode_number; // 200
    uint32_t unknown_10; // 204
    uint32_t unknown_11; // 208
    uint32_t unknown_12; // 212
    uint32_t unknown_13; // 216
    uint32_t unknown_14; // 220
    uint32_t unknown_15; // 224
    uint32_t unknown_16; // 228
    uint32_t gapless_data; // 232
    uint32_t unknown_17; // 236
    uint16_t gapless_track_flag; // 240
    uint16_t gapless_album_flag; // 242
    char unknown_18[20]; // 244
    uint32_t unknown_19; // 264
    uint32_t unknown_20; // 268
    uint32_t unknown_21; // 272
    uint32_t unknown_22; // 276
    uint16_t unknown_23; // 290
    uint16_t album_id; // 292

    /**
     * @brief Format the tracks filename.
     * @param format : template of the filename to generate
     * @param remove_illegal_characters : true to remove characters which may be
     *      illegal on some filesystems (as of now : /\:*?\"<>|)
     * @param illegal_character_replacement : character used to replace illegal
     *      characters
     * 
     * The format parameters interprets the following tags :
     *   - <album>
     *   - <artist>
     *   - <composer>
     *   - <disk_number>
     *   - <genre>
     *   - <title>
     *   - <total_disks>
     *   - <total_tracks>
     *   - <track_number>
     *   - <year>
     */
    QString filename(QString const & format,
                     bool remove_illegal_characters=true,
                     QString const & illegal_characters_replacement=QString("_")) const;

private :
    static std::map<QString, DataObjectType::Type> field_name_to_data_object_type_;
    static bool const initialized;
    
    static bool initialize_static_data();
};

BABELPOD_EXPORT std::istream & operator>>(std::istream & stream, Track & track);

#endif // e514f7ef_0c79_4e84_80d1_334b44c564b2
